package com.itheima.youdianda.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.youdianda.entity.YddCate;
import com.itheima.youdianda.entity.YddTag;
import com.itheima.youdianda.mapper.YddTagMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.youdianda.service.YddTagService;
import com.itheima.youdianda.util.MyPages;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2022-05-24
 */
@Service
public class YddTagServiceImpl extends ServiceImpl<YddTagMapper, YddTag> implements YddTagService {

	@Override
	public MyPages<YddTag> listByPage(String tagname, String page, String limit) {
		Page<YddTag> page1 = new Page<>(Long.parseLong(page), Long.parseLong(limit));
		MyPages<YddTag> myPage = new MyPages<>();
		LambdaQueryWrapper<YddTag> wrapper = new LambdaQueryWrapper<>();
		wrapper.like(StringUtils.isNotEmpty(tagname),YddTag::getTagname, tagname);
		this.page(page1,wrapper);

		myPage.setCount(page1.getTotal());
		myPage.setTotalPages(page1.getPages());
		myPage.setPageSize(page1.getSize());
		myPage.setCurrentPage(page1.getCurrent());
		myPage.setData(page1.getRecords());
		return myPage;
	}
}
